let strs = ['flower', 'flow', 'flight']
var longestCommonPrefix = function (strs) {
    if (strs.length === 0) {
        return ""
    }
    let ans = strs[0]
    for (let i = 1; i < strs.length; i++) {
        let arr = strs[i]
        let j = 0
        for (; j < ans.length && j < arr.length; j++) {
            if (ans[j] !== arr[j]) { break }
        }
        if (ans.length === 0) {
            ans = ""
        }
        ans = ans.substr(0, j)
    }
    return ans
};
console.log(longestCommonPrefix(strs));
